Skip to content

Support proxy_server_ready_backends metric #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

maqiuyujoyce
Copy link
Contributor

@maqiuyujoyce maqiuyujoyce commented Jun 27, 2025

Fixes #294
Prior art: #295

Added a new metric to track the total number of backends based on proxy strategy. To avoid circular import, I extracted out ProxyStrategy related types, functions and tests into a separate package.

I didn't overwrite the existent proxy_server_ready_backend_connections metric because of potential backwards compatibility concern brought up here: https://github.com/kubernetes-sigs/apiserver-network-proxy/pull/295/files#r872839718 Instead, I marked the problematic proxy_server_ready_backend_connections metric deprecated in the help message.

Tested locally following this example and got the following result when supporting both default and desthost backend managers:

# HELP konnectivity_network_proxy_server_ready_backend_connections Number of konnectivity agent connected to the proxy server
# TYPE konnectivity_network_proxy_server_ready_backend_connections gauge
konnectivity_network_proxy_server_ready_backend_connections 1
# HELP konnectivity_network_proxy_server_ready_backend_connections_total Total number of konnectivity agent connected to the proxy server
# TYPE konnectivity_network_proxy_server_ready_backend_connections_total gauge
konnectivity_network_proxy_server_ready_backend_connections_total{proxy_strategy="default"} 1
konnectivity_network_proxy_server_ready_backend_connections_total{proxy_strategy="destHost"} 1

Added unit tests for the new metric as well.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 27, 2025
@k8s-ci-robot k8s-ci-robot requested review from elmiko and tallclair June 27, 2025 03:12
@k8s-ci-robot
Copy link
Contributor

Hi @maqiuyujoyce. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2025
@jkh52
Copy link
Contributor

jkh52 commented Jun 27, 2025

/ok-to-test

Did you consider using ProxyStrategy in the new metric? It would be nice to keep *Manager and *Storage types as implementation details. The proxy server already exposes --proxy-strategies to the cluster admin.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 27, 2025
@@ -284,6 +299,11 @@ func (s *ServerMetrics) SetBackendCount(count int) {
s.backend.WithLabelValues().Set(float64(count))
}

// SetTotalBackendCount sets the total number of backend connection.
func (s *ServerMetrics) SetTotalBackendCount(managerName string, count int) {
s.totalBackendCount.WithLabelValues(managerName).Set(float64(count))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels can generate cardinality issues. I don't think this is likely to be a problem but we can reassure/protect ourselves by changing managerName from a string (unbounded cardinality) to an enumeration with an observation on limiting the number of options.

Copy link
Contributor Author

@maqiuyujoyce maqiuyujoyce Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Based on @jkh52 's suggestion above, I used proxy strategy enum as the label. (Thank you @jkh52 !)
It introduced the circular dependency, so I extracted out ProxyStrategy related types and functions into a separate package, and many files were updated. I can split it out into a separate PR if you prefer!

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2025
@jkh52
Copy link
Contributor

jkh52 commented Jun 30, 2025

I think there will remain a bug in ready_backend_connections (it gets clobbered when the server has more than one strategy). We could mark it deprecated (pkg/agent metrics has a help text example of this) if we think that will never get fixed.

@maqiuyujoyce maqiuyujoyce force-pushed the 202506-total-backend-metric branch from e72d63b to 565867c Compare July 1, 2025 21:10
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 1, 2025
@maqiuyujoyce
Copy link
Contributor Author

I think there will remain a bug in ready_backend_connections (it gets clobbered when the server has more than one strategy). We could mark it deprecated (pkg/agent metrics has a help text example of this) if we think that will never get fixed.

Done.

@maqiuyujoyce
Copy link
Contributor Author

@jkh52 Also moved the tests into this PR according to your suggestion. Please take a look!

prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Name: "ready_backend_connections_total",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final concern: the _total suffix here seems to contradict prometheus naming conventions (it implies a counter metric, not gauge).

Maybe just "ready_backends" or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@maqiuyujoyce maqiuyujoyce changed the title Support proxy_server_ready_backend_connections_total metric Support proxy_server_ready_backends metric Jul 2, 2025
@jkh52
Copy link
Contributor

jkh52 commented Jul 3, 2025

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 3, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jkh52, maqiuyujoyce

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 3, 2025
@k8s-ci-robot k8s-ci-robot merged commit 71d3800 into kubernetes-sigs:master Jul 3, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] The backend ServerMetric is not correct
4 participants